package com.ruoyi.LXHappointment.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.behindContract.service.IDocContractQBService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.LXHappointment.domain.LXHAppointment;
import com.ruoyi.LXHappointment.service.ILXHAppointmentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 个人预约就诊Controller
 * 
 * @author ruoyi
 * @date 2025-08-18
 */
@RestController
@RequestMapping("/LXHappointment/LXHDOCappointment")
public class LXHAppointmentController extends BaseController
{
    @Autowired
    private ILXHAppointmentService lXHAppointmentService;

    @Autowired
    private IDocContractQBService docContractService;


    /**
     * 校验用户是否有签约团队
     */
    @GetMapping("/checkUserHasContract")
    public AjaxResult checkUserHasContract(@RequestParam Long userId) {
        // 查询用户是否有签约团队ID
        Long teamId = docContractService.getUserTeamId(userId);
        if (teamId == null) {
            return AjaxResult.error("需要签约团队");
        }
        return AjaxResult.success(teamId);
    }



    /**
     * 查询个人预约就诊列表
     */
    @PreAuthorize("@ss.hasPermi('LXHappointment:LXHDOCappointment:list')")
    @GetMapping("/list")
    public TableDataInfo list(LXHAppointment lXHAppointment) {
        startPage();
        List<LXHAppointment> list = lXHAppointmentService.selectLXHAppointmentList(lXHAppointment);
        return getDataTable(list);
    }


    /**
     * 导出个人预约就诊列表
     */
    @PreAuthorize("@ss.hasPermi('LXHappointment:LXHDOCappointment:export')")
    @Log(title = "个人预约就诊", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LXHAppointment lXHAppointment)
    {
        List<LXHAppointment> list = lXHAppointmentService.selectLXHAppointmentList(lXHAppointment);
        ExcelUtil<LXHAppointment> util = new ExcelUtil<LXHAppointment>(LXHAppointment.class);
        util.exportExcel(response, list, "个人预约就诊数据");
    }

    /**
     * 获取个人预约就诊详细信息
     */
    @PreAuthorize("@ss.hasPermi('LXHappointment:LXHDOCappointment:query')")
    @GetMapping(value = "/{appId}")
    public AjaxResult getInfo(@PathVariable("appId") Long appId)
    {
        return success(lXHAppointmentService.selectLXHAppointmentByAppId(appId));
    }

    /**
     * 新增个人预约就诊
     */
    @PreAuthorize("@ss.hasPermi('LXHappointment:LXHDOCappointment:add')")
    @Log(title = "个人预约就诊", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LXHAppointment lXHAppointment) {
        return toAjax(lXHAppointmentService.insertLXHAppointment(lXHAppointment));
    }

    /**
     * 修改个人预约就诊
     */
    @PreAuthorize("@ss.hasPermi('LXHappointment:LXHDOCappointment:edit')")
    @Log(title = "个人预约就诊", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LXHAppointment lXHAppointment)
    {
        return toAjax(lXHAppointmentService.updateLXHAppointment(lXHAppointment));
    }

    /**
     * 删除个人预约就诊
     */
    @PreAuthorize("@ss.hasPermi('LXHappointment:LXHDOCappointment:remove')")
    @Log(title = "个人预约就诊", businessType = BusinessType.DELETE)
	@DeleteMapping("/{appIds}")
    public AjaxResult remove(@PathVariable Long[] appIds)
    {
        return toAjax(lXHAppointmentService.deleteLXHAppointmentByAppIds(appIds));
    }
}
